<template>
  <el-dialog
    title='添加违法行为'
    :visible.sync="dialogVisible"
    @opened="dialogOpen"
  >
    <el-form
      ref="form"
      :model="form"
      label-width="80px"
      size="small"
    >
      <el-form-item
        prop="zfmlId"
        label="执法门类"
      >
        <el-select v-model="form.zfmlId" placeholder="请选择">
              <el-option
                v-for="item in publics"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
      </el-form-item>
      <el-form-item
        prop="casecauseNumber"
        label="违法行为编号"
      >
        <el-input v-model="form.casecauseNumber"></el-input>
      </el-form-item>
      <el-form-item
        prop="content"
        label="违法行为内容"
      >
        <el-input v-model="form.content"></el-input>
      </el-form-item>
      <el-form-item
        prop="remark"
        label="说明"
      >
        <el-input v-model="form.remark"></el-input>
       </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :loading="loading"
          @click="saveUser"
        >保存</el-button>
        <el-button @click="close">取消</el-button>
      </el-form-item>
    </el-form>

  </el-dialog>

</template>
<script>
import casecauseApi from "@/api/system/casecause";
import publicApi from "@/api/system/sysPublic";
export default {
  name: "casecauseAddForm",
  props: {
    value: Boolean
  },
  data() {
    return {
      loading: false,
      dialogVisible: false,
      form: {
        content: "",
        casecauseNumber: "",
        remark: "",
        zfmlId:""
      },
      publics: []
    };
  },
  watch: {
    value(val) {
      this.dialogVisible = val;
    },
    dialogVisible(val) {
      this.$emit("input", val);
    }
  },
  methods: {
    dialogOpen() {
      this.$refs.form.resetFields();
      this.getPublicByType("0055");
    },
    getPublicByType(type) {
      publicApi.getPublicByType({ type: type }).then(res => {
        var data = res.data;
        this.publics = data;
      });
    },
    saveUser() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.loading = true;
          casecauseApi
            .add({ ...this.form,})
            .then(data => {
              this.loading = false;
              this.dialogVisible = false;
              this.$emit("submit");
            });

        } else {
          return false;
        }
      });
    },
    close() {
      this.$refs["form"].resetFields();
      this.dialogVisible = false;
    }
  }
};
</script>

